Skip to content

Add status code helper#5

Merged
RAprogramm merged 4 commits intomainfrom
codex/add-status_code-method-and-tests
Sep 11, 2025
Merged

Add status code helper#5
RAprogramm merged 4 commits intomainfrom
codex/add-status_code-method-and-tests

Conversation

@RAprogramm
Copy link
Owner

Summary

  • expose ErrorResponse::status_code to map numeric status into http::StatusCode
  • refactor axum and actix integrations to use status_code()
  • cover status_code() with a unit test

Testing

  • cargo +nightly fmt --
  • cargo clippy -- -D warnings
  • cargo build --all-targets
  • cargo test --all
  • cargo doc --no-deps --all-features
  • cargo audit (fails: 1 vulnerability found in rsa via sqlx)

https://chatgpt.com/codex/tasks/task_e_68c26567096c832b849613040e855943

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex Review: Here are some suggestions.

Reply with @codex fix comments to fix any unresolved comments.

About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you open a pull request for review, mark a draft as ready, or comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex fix this CI failure" or "@codex address that feedback".

@RAprogramm
Copy link
Owner Author

@codex
Updating crates.io index
Checking masterror v0.3.2 (/home/runner/work/masterror/masterror)
error[E0308]: mismatched types
--> src/response.rs:329:51
|
329 | let mut builder = HttpResponse::build(status);
| ------------------- ^^^^^^ expected actix_web::http::StatusCode, found http::StatusCode
| |
| arguments to this function are incorrect
|
note: two different versions of crate http are being used; two types coming from two different versions of the same crate are different types even if they look the same
--> /home/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/http-0.2.12/src/status.rs:45:1
|
45 | pub struct StatusCode(NonZeroU16);
| ^^^^^^^^^^^^^^^^^^^^^ this is the expected type actix_web::http::StatusCode
|
::: /home/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/http-1.3.1/src/status.rs:45:1
|
45 | pub struct StatusCode(NonZeroU16);
| ^^^^^^^^^^^^^^^^^^^^^ this is the found type http::StatusCode
|
::: src/convert/actix.rs:64:5
|
64 | use actix_web::{HttpResponse, ResponseError, http::StatusCode as ActixStatus};
| --------- one version of crate http used here, as a dependency of crate actix_http
|
::: src/response.rs:60:5
|
60 | use http::StatusCode;
| ---- one version of crate http used here, as a direct dependency of the current crate
= help: you can use cargo tree to explore your dependency tree
note: associated function defined here
--> /home/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/actix-web-4.11.0/src/response/response.rs:40:12
|
40 | pub fn build(status: StatusCode) -> HttpResponseBuilder {
| ^^^^^

For more information about this error, try rustc --explain E0308.
error[E0599]: no method named status_code found for enum std::result::Result in the current scope
--> src/response.rs:381:26
|
381 | assert_eq!(valid.status_code(), StatusCode::NOT_FOUND);
| ^^^^^^^^^^^ method not found in std::result::Result<response::ErrorResponse, app_error::AppError>
|
note: the method status_code exists on the type response::ErrorResponse
--> src/response.rs:191:5
|
191 | pub fn status_code(&self) -> StatusCode {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: consider using Result::expect to unwrap the response::ErrorResponse value, panicking if the value is a Result::Err
|
381 | assert_eq!(valid.expect("REASON").status_code(), StatusCode::NOT_FOUND);
| +++++++++++++++++

error: could not compile masterror (lib) due to 1 previous error
warning: build failed, waiting for other jobs to finish...
error[E0599]: no method named status_code found for enum std::result::Result in the current scope
--> src/response.rs:384:28
|
384 | assert_eq!(invalid.status_code(), StatusCode::INTERNAL_SERVER_ERROR);
| ^^^^^^^^^^^ method not found in std::result::Result<response::ErrorResponse, app_error::AppError>
|
note: the method status_code exists on the type response::ErrorResponse
--> src/response.rs:191:5
|
191 | pub fn status_code(&self) -> StatusCode {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: consider using Result::expect to unwrap the response::ErrorResponse value, panicking if the value is a Result::Err
|
384 | assert_eq!(invalid.expect("REASON").status_code(), StatusCode::INTERNAL_SERVER_ERROR);
| +++++++++++++++++

Some errors have detailed explanations: E0308, E0599.
For more information about an error, try rustc --explain E0308.
error: could not compile masterror (lib test) due to 3 previous error

@chatgpt-codex-connector
Copy link

Summary

  • Converted the Actix responder to translate the helper’s http::StatusCode into Actix’s own StatusCode before building the response, resolving the earlier type mismatch src/response.rsL315-L334
  • Expanded the status_code tests to unwrap valid results and manually construct an invalid ErrorResponse, ensuring fallback to INTERNAL_SERVER_ERROR works correctly src/response.rsL381-L396

Testing

  • cargo +nightly fmt --
  • cargo clippy -- -D warnings
  • cargo build --all-targets
  • cargo test --all
  • cargo doc --no-deps --all-features
  • cargo audit (1 vulnerability found in rsa via sqlx)
  • cargo check --no-default-features --features axum
  • cargo check --no-default-features --features actix

View task →

@RAprogramm RAprogramm merged commit 679e676 into main Sep 11, 2025
1 of 2 checks passed
@RAprogramm RAprogramm deleted the codex/add-status_code-method-and-tests branch September 11, 2025 06:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant